package org.dce.screencapturer.objects;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Path2D;

import org.dce.screencapturer.actions.drawing.InsertObjectAction;
import org.dce.screencapturer.util.IconFactory;

@SuppressWarnings("serial")
public class StaredEllipse extends RegularShapeObject {

	public static final class InsertAction extends InsertObjectAction {
		public InsertAction(){
			super("actions.starredEllipse",IconFactory.getIcon("/images/star.png"), null,StaredEllipse.class);
		}
	};

	@Override
	protected Rectangle calculateInnerBounds(Shape shape) {

		final int width = getWidth();
		final int height = getHeight();
		
		final int areaWidth = (int)(width * 0.4);
		final int areaHeight = (int)(height * 0.4);

		final int offsetX = (width - areaWidth )/2;
		final int offsetY = (height - areaHeight )/2;

		return new Rectangle(offsetX,offsetY,areaWidth,areaHeight);
	}

	@Override
	protected Shape getShape() {
		
		int x = left.getCenterX();
		int y = top.getCenterY();
		
		final int width = right.getCenterX()-x;
		final int height = bottom.getCenterY()-y;
		
		final double radiusX1 = width / 2.0;
		final double radiusX2 = width * 0.4;
		final double radiusY1 = height / 2.0;
		final double radiusY2 = height * 0.4;
		
		final int centerX = x + width / 2;
		final int centerY = y + height / 2;
		
		final double delta = Math.PI / 18.0; 

		Path2D path = new Path2D.Double();
		path.moveTo(centerX+radiusX1, centerY);

		double angle = 0;

		for (int i=0;i<18;i++){
			
			angle+= delta;
			
			path.lineTo(
				centerX + Math.cos(angle)*radiusX2, 
				centerY + Math.sin(angle)*radiusY2);

			angle+= delta;
			
			path.lineTo(
				centerX + Math.cos(angle)*radiusX1, 
				centerY + Math.sin(angle)*radiusY1);
		}
		
		path.closePath();
		
		return path;
	}
	

}
